package com.ruoyi.records.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.records.domain.BorrowRecords;
import com.ruoyi.records.service.IBorrowRecordsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 借阅记录Controller
 * 
 * @author anyunyi
 * @date 2025-05-28
 */
@RestController
@RequestMapping("/records/dept")
public class BorrowRecordsController extends BaseController
{
    @Autowired
    private IBorrowRecordsService borrowRecordsService;

    /**
     * 查询借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('records:dept:list')")
    @GetMapping("/list")
    public TableDataInfo list(BorrowRecords borrowRecords)
    {
        startPage();
        List<BorrowRecords> list = borrowRecordsService.selectBorrowRecordsList(borrowRecords);
        return getDataTable(list);
    }

    /**
     * 导出借阅记录列表
     */
    @PreAuthorize("@ss.hasPermi('records:dept:export')")
    @Log(title = "借阅记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BorrowRecords borrowRecords)
    {
        List<BorrowRecords> list = borrowRecordsService.selectBorrowRecordsList(borrowRecords);
        ExcelUtil<BorrowRecords> util = new ExcelUtil<BorrowRecords>(BorrowRecords.class);
        util.exportExcel(response, list, "借阅记录数据");
    }

    /**
     * 获取借阅记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('records:dept:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(borrowRecordsService.selectBorrowRecordsById(id));
    }

    /**
     * 新增借阅记录
     */
    @PreAuthorize("@ss.hasPermi('records:dept:add')")
    @Log(title = "借阅记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BorrowRecords borrowRecords)
    {
        return toAjax(borrowRecordsService.insertBorrowRecords(borrowRecords));
    }

    /**
     * 修改借阅记录
     */
    @PreAuthorize("@ss.hasPermi('records:dept:edit')")
    @Log(title = "借阅记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BorrowRecords borrowRecords)
    {
        return toAjax(borrowRecordsService.updateBorrowRecords(borrowRecords));
    }

    /**
     * 删除借阅记录
     */
    @PreAuthorize("@ss.hasPermi('records:dept:remove')")
    @Log(title = "借阅记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(borrowRecordsService.deleteBorrowRecordsByIds(ids));
    }
}
